unit uRoomDM;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,  FMTBcd, DBClient, Provider, DB, SqlExpr, uAbstractDataModule ;

type
  TRoomDM = class(TAbstractDataModule)
    cdsControlCAPACITY: TStringField;
    cdsControlLOCATION: TStringField;
    cdsControlNAME: TStringField;
    cdsControlROOM_ID: TIntegerField;
    procedure cdsControlBeforePost(DataSet: TDataSet);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  RoomDM: TRoomDM;

implementation
uses uRoomControl;
{$R *.dfm}

procedure TRoomDM.cdsControlBeforePost(DataSet: TDataSet);
begin
  //CheckRequiredFields(DataSet);
  if TRoomControl.GetInstance.FindRoomName(
                              DataSet.FieldByName('ROOM_ID').AsInteger,
                              DataSet.FieldByName('NAME').AsString) then
  raise Exception.Create('Duplicated room name');
  if DataSet.State=dsInsert then
    DataSet.FieldByName('ROOM_ID').AsInteger:=GenerateID('GEN_ROOM_ID');


end;

end.
